<template>
  <div class="container" v-if="pageAuth">
    <page-header :title="$t('m.settingBattery')" :has-return="true">
    </page-header>

    <div class="detail_div">
      <div class="detail_left">
        <div class="detail_left_div">
          <el-form ref="form" :model="form" :rules="rules">
            <div class="create_title2" style="padding-bottom:8px;">
              {{ $t('m.settingRentalMinBattery') }}
            </div>
            <div
              class="create_title2"
              style="font-size: 14px;line-height: 20px;font-weight:400;"
            >
              {{ $t('m.settingRentalMinBatteryHint') }}
            </div>
            <el-form-item prop="low-power-standard">
              <el-input
                v-model="form['low-power-standard']"
                :placeholder="$t('m.Please_enter')"
                @input="changeElectric"
                :maxlength="3"
                clearable
              >
                <template slot="append">%</template>
              </el-input>
            </el-form-item>
          </el-form>
          <div class="create_button">
            <el-button
              class="el_button"
              @click="submit()"
              :disabled="disabled"
              type="primary"
              >{{ $t('m.save') }}</el-button
            >
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>

export default {
  data () {
    return {
      form: {
        'low-power-standard': ''
      },
      rules: {
        'low-power-standard': this.$rule.required
      },
      pageAuth: this.permissionsId(220),
      disabled: true
    }
  },
  created () {
    if (!this.pageAuth) {
      return
    }
    this.getConfigs()
  },
  methods: {
    changeElectric (val) {
      this.disabled = false
      this.form['low-power-standard'] = this.$check.noZero(val)
      if (this.form['low-power-standard'] > 100) {
        this.form['low-power-standard'] = 100
      }
    },
    getConfigs () {
      this.$api.setting.getConfigs().then(res => {
        if (this.$ok(res)) {
          this.form['low-power-standard'] = res.data['low-power-standard']
        }
      })
    },
    // 提交
    submit () {
      // console.log('submit', this.form)
      this.$refs.form.validate(valid => {
        if (!valid) {
          return
        }
        const params = this.$util.map2listForConfig(this.form)
        this.$api.setting.batchModifyConfigs(params).then(res => {
          if (this.$ok(res)) {
            this.$message.success(res.message)
            this.disabled = true
            this.getConfigs()
          } else {
            this.$message.error(res.message)
          }
        })
      })
    }
  }
}
</script>
<style scoped lang="scss">
.container {
  width: 100%;
  min-width: 1000px !important;
  // max-width: 1000px !important;

  .page-header {
    padding: 20px 0;
  }

  .page-header,
  .detail_div,
  .detail_left {
    width: 100% !important;
    min-width: 1000px !important;
    max-width: 1000px !important;
  }

  .detail_div,
  .detail_left {
    margin: 0 !important;
  }

  .detail_left_div {
    padding-bottom: 20px;
    margin-top: 0;
    ::v-deep .el-input__inner {
      border-radius: 4px 0 0 4px;
    }
  }

  .el-form {
    width: 490px;
  }
}
.create_button {
  margin-top: 12px;
  .el_button {
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    color: #ffffff;
    line-height: 16px;
    border: none;
    padding: 10px 48px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
@media screen and (min-width: 1221px) {
  .container {
    display: flex;
    justify-content: center;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
  }
}
</style>
